{extend name="adminblue/base" /}
{block name="resources"/}
{/block}
{block name="right_tab"}
<li><a href="javascript:;" onclick="addBrand()"><i class="fa fa-plus-circle"></i>&nbsp;添加品牌</a></li>
{/block}
{block name="main"}
<div class="operation">
	<a class="btn btn-small" href="javascript:batchDelete()">批量删除</a>
</div>
<table class="table-class">
	<colgroup>
		<col style="width: 1%;">
		<col style="width: 8%;">
		<col style="width: 11%;">
		<col style="width: 11%;">
		<col style="width: 12%;">
	</colgroup>
	<thead>
		<tr>
			<th><input type="checkbox" onclick="CheckAll(this)" /></th>
			<th>图片</th>
			<th>品牌名称</th>
			<th>品牌首字母</th>
			<th>操作</th>
		</tr>
	</thead>
	<colgroup>
		<col style="width: 5%;">
		<col style="width: 8%;">
		<col style="width: 11%;">
		<col style="width: 11%;">
		<col style="width: 12%;">
	</colgroup>
	<tbody></tbody>
</table>
{/block}
{block name="script"}
<script type="text/javascript">
/* 跳转到添加品牌 */
function addBrand() {
	location.href = __URL("ADMIN_MAIN/goods/addgoodsbrand");
}

//批量删除
function batchDelete(){
	var brand_ids = new Array();
	$(".table-class tbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			brand_ids.push($(this).val());
		}
	});
	if(brand_ids.length==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#e57373": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	delBrand(brand_ids);
}

//加载数据
function LoadingInfo(page_index) {
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/goods/goodsbrandlist')}",
		data : {
			"page_index" : page_index,
			"page_size" : $("#showNumber").val()
		},
		success : function(data) {
			var html = '';
			if (data["data"].length > 0) {
				for (var i = 0; i < data["data"].length; i++) {
					html += '<tr align="center">';
					html += '<td><input name="sub" type="checkbox" value="'+ data["data"][i]["brand_id"] +'" ></td>';
					if(data["data"][i]["brand_pic"]==''){
						html += '<td></td>';
					}else{
						html += '<td><img src="__UPLOAD__/'+ data["data"][i]["brand_pic"] +'" style="height:25px;"></td>';
					}
					html += '<td>' + data["data"][i]["brand_name"] + '</td>';
					html += '<td>' + data["data"][i]["brand_initial"] + '</td>';
					html += '<td><a href="'+__URL('ADMIN_MAIN/goods/updategoodsbrand?brand_id=' + data["data"][i]["brand_id"] )+ '">修改</a>  <a href="javascript:delBrand(' + data["data"][i]["brand_id"] + ')">删除</a></td> ';
					html += '</tr>';
				}
			} else {
				html += '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
			}
			$(".table-class tbody").html(html);
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

/* 删除品牌 */
function delBrand(brand_id) {
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$(this).dialog('close');
				$.ajax({
					type : "post",
					url : "{:__URL('ADMIN_MAIN/goods/deletegoodsbrand')}",
					data : { 'brand_id' : brand_id.toString() },
					dataType : "json",
					success : function(data) {
						if (data['code'] > 0) {
							LoadingInfo(getCurrentIndex(brand_id,'.table-class tbody'));
							showMessage('success', data["message"]);
						}else{
							showMessage('error', data["message"]);
						}
					}
				});
			},"取消,#e57373" : function(){
				$(this).dialog('close');
			}
		},
		contentText:"你确定删除吗？",
		title:"消息提醒"
	});
}

//全选
function CheckAll(event){
	var checked = event.checked;
	$(".table-class tbody input[type = 'checkbox']").prop("checked",checked);
}
</script>
{/block}